package org.dxy.domain.model.aggregate.factory.impl;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dxy.domain.command.process.CreateProcessCommand;
import org.dxy.domain.model.aggregate.factory.ProcessFactory;
import org.dxy.domain.model.aggregate.Process;
import org.springframework.stereotype.Component;

/**
 * 工序工厂实现类
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class ProcessFactoryImpl implements ProcessFactory {
    
    @Override
    public Process create(Long processId, CreateProcessCommand command) {
        // 业务规则校验
        validateCreateCommand(command);
        
        // 直接创建完整的工序聚合根
        Process process = Process.create(processId, command);
        
        log.info("工序聚合根创建成功, processId={}", processId);
        
        return process;
    }
    
    /**
     * 校验创建工序命令
     * @param command 创建工序命令
     */
    private void validateCreateCommand(CreateProcessCommand command) {
        if (command == null) {
            throw new IllegalArgumentException("创建工序命令不能为空");
        }

    }
}